﻿
// SerialThreadDlg.h: 头文件
//

#pragma once
#include "DigiStatic_src\Digistatic.h"
#include "Led\Led.h"
#include "SerialThread.h"
#include "SerialThreadManager.h"
#include "MinsListDlg.h"
#include "SinsListDlg.h"
#include "GNSSListDlg.h"
#include "PRngListDlg.h"
#include "EphmListDlg.h"
#include "RTKGListDlg.h"
#include "NavChart.h"
#include "NavStore.h"

#define DEG		0.0174533

// CJointSerialTestDlg 对话框
class CJointSerialTestDlg : public CDialogEx
{
// 构造
public:
	CJointSerialTestDlg(CWnd* pParent = nullptr);	// 标准构造函数
	~CJointSerialTestDlg();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_SERIALTHREAD_DIALOG };
#endif

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持


// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	// LED 1~5
	CLed led_S1, led_S2, led_S3, led_S4, led_S5, led_save;
	void LEDInit();

	// 串口开关
	CButton btnMINS, btnSINS, btnGNSS, btnPRE, btnRTK;
	afx_msg void OnBnClickedButtonComS1();
	afx_msg void OnBnClickedButtonComS2();
	afx_msg void OnBnClickedButtonComS3();
	afx_msg void OnBnClickedButtonComS4();
	afx_msg void OnBnClickedButtonComS5();

	// 下拉菜单
	CComboBox ComboDevS1, ComboDevS2, ComboDevS3, ComboDevS4, ComboDevS5;
	CComboBox ComboComS1, ComboComS2, ComboComS3, ComboComS4, ComboComS5;
	CComboBox ComboBdrS1, ComboBdrS2, ComboBdrS3, ComboBdrS4, ComboBdrS5;
	CComboBox ComboStpS1, ComboStpS2, ComboStpS3, ComboStpS4, ComboStpS5;
	CComboBox ComboPrtS1, ComboPrtS2, ComboPrtS3, ComboPrtS4, ComboPrtS5;
	void ComboInit();

	// 时间显示控件
	CEdit stateDisp;				// 状态栏
	CFont titleFont;				// 用于设置计时器字体
	SYSTEMTIME st = { 0 };		// 系统时间
	UINT secCounter = 0;
	UINT syscnt_ms[5] = { 0 };				// 系统ms计数，每一路数据一个
	BOOL counterPause = FALSE;
	CDigiStatic TimerDate, TimerTime, TimerCnte;
	CStatic textDate, textTime, textCnte;
	CButton btnTimerOn, btnTimerReset;
	void TimerInit();
	void SetLocalTime();
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	void OnBnClickedTimerStart();
	void OnBnClickedTimerReset();

	// 串口线程
	UINT syscnt_mins = 0, syscnt_sins = 0, syscnt_gnss = 0, syscnt_pre = 0, syscnt_rtk = 0;
	const CString errMBcont[5] = { L"主惯导", L"子惯导", L"GNSS", L"伪距/星历", L"RTK" };
	CHAR serialDataBuffer[9][4096] = { 0 };		// 串口缓冲区
	SerialThreadManager* serialMag;
	const int bdrlist[10] = { 2400, 4800,  9600,  19200, 38400,
							57600,115200,230400,460800,921600 };
	IMUDATA Mimudata, Simudata;
	GPGGADATA GNSSpos, RTKpos;
	BESTVELDATA GNSSvel, RTKvel;
	BOOL RTKon = FALSE;			// GNSS与RTK显示开关
	RANGETABLE		rngtab;
	SATEPOSTABLE		sattab;
	EPHEMRISETABLE	ephtab;		// 记录试验过程星历表，用于紧组合实时解算用
	BOOL				EPHReady;	// 星历读取完毕标志，用于星历数据保存
	SerialThread* thdMINS, * thdSINS, * thdGNSS, * thdPDE, * thdRTK;
	void threadsInit();
	afx_msg LRESULT SerialNotOpenPeocess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT MIDDataProcess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT SIDDataProcess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT GPODataProcess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT GVEDataProcess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT PPRDataProcess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT PSPDataProcess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT PEPDataProcess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT RPODataProcess(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT RVEDataProcess(WPARAM wParam, LPARAM lParam);
	
	// 数据显示
	CDigiStatic dispMDEV, dispMCNT, dispMTEM, dispMWX, dispMWY, dispMWZ,
				dispMFX, dispMFY, dispMFZ;
	CDigiStatic dispSDEV, dispSCNT, dispSTEM, dispSWX, dispSWY, dispSWZ,
				dispSFX, dispSFY, dispSFZ;
	CDigiStatic dispGTM, dispGNS, dispSTYP, dispDOP, dispGVF, dispGVU, dispYAW,
				dispLAT, dispLNT, dispALT;
	CButton GRSwitcher;
	void datadispinit();
	void addMIMUData();
	void addSIMUData();
	void addGNSSData();
	void addRTKGData();
	afx_msg void OnMsinslist();
	afx_msg void OnSinslist();
	afx_msg void OnGnsslist();
	afx_msg void OnPreplist();
	afx_msg void OnEphmlist();
	afx_msg void OnRtkglist();

	// 数据列表对话框
	MinsListDlg* MDlg;
	SinsListDlg* SDlg;
	GNSSListDlg* GDlg;
	PRngListDlg* PDlg;
	EphmListDlg* EDlg;
	RTKGListDlg* RDlg;

	// Chart对象
	NavChart* MGyro, * MAcce, * SGyro, * SAcce;
	void chartsInit();

	// 对话框关闭按钮
	afx_msg void OnDlgCloseBnClickedButton();

	// 数据存储
	BOOL isStoring = FALSE;
	CButton btn_store;
	NavStore ns;
	void fileioinit();
	afx_msg void OnBnClickedButtonDatastore();
	afx_msg void OnBnClickedButtonGrswitcher();
};
